'use strict';
//var options={sdate:'2015-04-16',edate:'2015-04-20'}
function count(){
var jobdata=new Vue({
        el: '#jobdata',
        data: {
        	option:{},
        	myChart:''
        },
        mounted :function(){
        	var that=this;
        	that.loadData();
        },
        methods: {
        	initChart:function(){
        		if(this.myChart=='')
        		this.myChart = echarts.init(document.getElementById('jobdata_chart'));
            	this.option = {
            	        title: {
            	            text: '数据统计',          	            
            	            x:'center',
            	            textAlign:'center'
            	        },
            	        tooltip: {show:true,
            	        	trigger:"axis",
            	        	axisPointer:{type:'cross'}/*,
            	        	formatter: function(params){
            	        		bubbleSort(params);
            	        		var res = "<font size='2'>"+params[0].axisValue+"</font><br>";
                                for(var i=0;i<params.length;i++){
                                	if(params[i].value!=0){
                                		res+='<font size="4" style=\"color:'+params[i].color+'\">●</font>'+params[i].seriesName+'：'+params[i].data+'<br>';
                                	}
                                }
                                
                                return res;
                            }*/
            	        },
            	        grid: {
            	            left: '3%',
            	            //right: '4%',
            	            bottom: '3%',
            	            containLabel: true
            	        },
            	        toolbox:{show:false,feature:{dataZoom:{yAxisIndex:false}}},
            	        legend: {
/*            	            data:[],
            	            left:'90%',
            	            bottom:40,
            	            orient:'vertical'*/
            	            data:[],
            	            top:32,
            	            right:'8%'
            	        },
            	        dataZoom:[{type:'slider',xAxisIndex:[0],start:0,end:100,showDetail:true}],
            	        xAxis: {
            	            data: []
            	        },
            	        yAxis: {},
            	        series: []
            	    };
        	},
        	loadData:function(){
        		var that=this;
        		this.initChart();
        		that.myChart.showLoading({text:"加载数据中...."});
        		// 加载项，赋值配置，X轴日期,类型,data  	
        		
        		// 动态请求数据
        		//setInterval(function(){},30000);
        		  that.option.legend.data=[];
        		  that.option.series=[];
        		  that.option.xAxis.data = [];
        			
		  	      axios.get('../jobsys/manager/countAll')
		      	  .then(function (response) {
		      		that.myChart.hideLoading();
		      		  var data=response.data;
		      		that.data=data;
		      		
		      		that.option.legend.data.push('日爬取量');
		      		var mod = {name:'日爬取量',type:'line',data:[]};
		      		that.option.series.push(mod);
		      		
		      		// x
		      		var date1 = new Date(data[0].publishtime);
		      		var date2 = new Date();
		      		while(date1<date2){
		      			var date = date1.getFullYear()+"-"+(date1.getMonth()+1)+"-"+date1.getDate();
		      			that.option.xAxis.data.push(date);
		      			date1.setDate(date1.getDate() + 1);
		      			that.option.series[0].data.push(0);
		      		}
		      		
		      		for(var i in data){
		      			var d = data[i];
		      			var date =new Date(d.publishtime);
		      			date = date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
		      			
		      			//that.option.xAxis.data.push(date);

			      		var index = that.option.xAxis.data.indexOf(date);
		      			that.option.series[0].data[index]=d.num;//.push([date,d.num]);	
		      		}
		      		
		      		that.option.legend.data.sort();
		  	      		 // 使用刚指定的配置项和数据显示图表。
		  	      	that.myChart.setOption(that.option);
		  	      	that.myChart.on('datazoom',function(event){
		  	        		  console.info(event)
		  	        		  var startIndex=(event.start/100)*(that.option.xAxis.data.length-1)
		  	        		  var endIndex=(event.end/100)*(that.option.xAxis.data.length-1);
		  	        		  let startStr=that.option.xAxis.data[Math.round(startIndex)];
		  	        		  let endStr=that.option.xAxis.data[Math.round(endIndex)];
		  	        		  // 当有日期变动是才执行
		  	        	  });
		      	  	});
        		
        	}
        }
    })
}